from flask import Flask, Blueprint
from flask_sqlalchemy import SQLAlchemy

# 创建应用实例
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///campus_secondhand.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'your-secret-key-here'

# 初始化数据库
db = SQLAlchemy(app)

# 创建主API蓝图
api_bp = Blueprint('api', __name__, url_prefix='/api')

# API根路由
@api_bp.route('/')
def api_info():
    """API基本信息端点"""
    return {
        'name': '校园二手商品交易系统API',
        'version': 'v1.0',
        'description': '提供校园二手商品交易系统的核心功能接口'
    }

# 注册蓝图
app.register_blueprint(api_bp)

# 基本路由
@app.route('/')
def hello():
    return "校园二手交易系统已启动!"

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000, debug=True)